package com.hzcx.app.simplechat.model;

import android.content.Context;

import com.hzcx.app.simplechat.api.APIRequest;
import com.hzcx.app.simplechat.api.BaseObserver;
import com.hzcx.app.simplechat.api.BaseResponse;
import com.hzcx.app.simplechat.api.RxHelper;
import com.hzcx.app.simplechat.base.BaseEmptyBean;
import com.hzcx.app.simplechat.ui.chat.ChatGroupSettingActivity;
import com.hzcx.app.simplechat.ui.chat.bean.GroupSearchBean;
import com.hzcx.app.simplechat.ui.friend.bean.GroupListBean;
import com.hzcx.app.simplechat.ui.group.bean.GroupCreateBean;
import com.hzcx.app.simplechat.ui.group.bean.GroupInfoBean;
import com.hzcx.app.simplechat.ui.group.bean.GroupJoinBean;
import com.hzcx.app.simplechat.ui.group.bean.ManagerMembersBean;
import com.hzcx.app.simplechat.ui.group.bean.MembersBean;
import com.hzcx.app.simplechat.ui.group.bean.QueryMembersBean;
import com.hzcx.app.simplechat.util.token.TokenUtils;

import java.util.List;

import io.reactivex.Observable;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.Header;
import retrofit2.http.Headers;
import retrofit2.http.POST;

public class GroupModel {
    /*
     *  获取我的群组接口
     */
    public static void getGroupList(Context context, BaseObserver<GroupListBean> observer) {
        APIRequest
                .getRequestInterface()
                .getGroupList(TokenUtils.getTokenHeader())
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /*
    * 查找群组
    */
    public static void searchGroupList(Context context, String groupID,String groupName, BaseObserver<List<GroupSearchBean>> observer) {
        APIRequest
                .getRequestInterface()
                .searchGroupList(TokenUtils.getTokenHeader(), groupID,groupName)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /*
     *  申请加群
     */
    public static void applyJoin(Context context, String groupID, String question, String answer, BaseObserver<GroupJoinBean> observer) {
        APIRequest
                .getRequestInterface()
                .joinGroup(TokenUtils.getTokenHeader(), groupID, question, answer)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /*
     *   设置消息免打扰
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48228469&shareCode=Va3gRz&shareToken=$2y$10$RTG0wyE~2FqTrDOUBOcEduNOEhO.Yf.sAM6Wak8bciXEaOZKgzwHWbC&shareID=284717
     */
    public static void addMembersGroup(Context context, String group_id, String member_ids, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .addMembersGroup(TokenUtils.getTokenHeader(), group_id, member_ids)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


    /*
     *   退出群组: 群主无法使用
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48228469&shareCode=Va3gRz&shareToken=$2y$10$RTG0wyE~2FqTrDOUBOcEduNOEhO.Yf.sAM6Wak8bciXEaOZKgzwHWbC&shareID=284717
     */
    public static void deleteMembersGroup(Context context, String group_id, String member_ids, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .deleteMembersGroup(TokenUtils.getTokenHeader(), group_id, member_ids)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


   /*
    *   创建群组
    *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48194609&shareCode=Va3gRz&shareToken=$2y$10$RTG0wyE~2FqTrDOUBOcEduNOEhO.Yf.sAM6Wak8bciXEaOZKgzwHWbC&shareID=284717
    */
    public static void createGroup(Context context, String member_ids, BaseObserver<GroupCreateBean> observer) {
        APIRequest
                .getRequestInterface()
                .createGroup(TokenUtils.getTokenHeader(), member_ids)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /*
     *   群组详情
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48229629&shareCode=Va3gRz&shareToken=$2y$10$RTG0wyE~2FqTrDOUBOcEduNOEhO.Yf.sAM6Wak8bciXEaOZKgzwHWbC&shareID=284717
     */
    public static void getGroupInfo(Context context, String group_id, BaseObserver<GroupInfoBean> observer) {
        APIRequest
                .getRequestInterface()
                .getGroupInfo(TokenUtils.getTokenHeader(), group_id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


    public static void getGroupMembers(Context context, String group_id,String page,String page_size, BaseObserver<QueryMembersBean> observer) {
        APIRequest
                .getRequestInterface()
                .getGroupMembers(TokenUtils.getTokenHeader(), group_id,page,page_size)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


    public static void queryGroupMembers(Context context,String keyword, String group_id,String page,String page_size, BaseObserver<QueryMembersBean> observer) {
        APIRequest
                .getRequestInterface()
                .queryGroupMembers(TokenUtils.getTokenHeader(), group_id,page,page_size,keyword)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    public static void getGroupMemberIds(Context context,String group_id, BaseObserver<List<String>> observer) {
        APIRequest
                .getRequestInterface()
                .getGroupMemberIds(TokenUtils.getTokenHeader(), group_id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    public static void getGroupManagers(Context context, String group_id,String page,String page_size, BaseObserver<List<ManagerMembersBean>> observer) {
        APIRequest
                .getRequestInterface()
                .getGroupManagers(TokenUtils.getTokenHeader(), group_id,page,page_size)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /*
     *   修改群组名称
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48229927&shareCode=Va3gRz&shareToken=$2y$10$UqvpXk54T9YMqudE6PR7YOtv6E4UBA03NZIR7H6ccu4.6BoAtGQCq&shareID=284717
     */
    public static void modifyGroupName(Context context, String group_id, String group_name, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .modifyGroupName(TokenUtils.getTokenHeader(), group_id, group_name)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


    /*
     *   修改群组名片：即我在群中的昵称
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48229927&shareCode=Va3gRz&shareToken=$2y$10$UqvpXk54T9YMqudE6PR7YOtv6E4UBA03NZIR7H6ccu4.6BoAtGQCq&shareID=284717
     */
    public static void modifyGroupNickName(Context context, String group_id, String nickname, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .modifyGroupNickName(TokenUtils.getTokenHeader(), group_id, nickname)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


    /*
     *   修改群组描述
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48229525&shareCode=Va3gRz&shareToken=$2y$10$UqvpXk54T9YMqudE6PR7YOtv6E4UBA03NZIR7H6ccu4.6BoAtGQCq&shareID=284717
     */
    public static void modifyGroupDescription(Context context, String group_id, String description, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .modifyGroupDescription(TokenUtils.getTokenHeader(), group_id, description)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }






    /*
     *   修改群组公告
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48211925&shareCode=Va3gRz&shareToken=$2y$10$UqvpXk54T9YMqudE6PR7YOtv6E4UBA03NZIR7H6ccu4.6BoAtGQCq&shareID=284717
     */
    public static void modifyGroupMotice(Context context, String group_id, String announcement, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .modifyGroupMotice(TokenUtils.getTokenHeader(), group_id, announcement)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /*
     *   修改群组保护
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48211925&shareCode=Va3gRz&shareToken=$2y$10$UqvpXk54T9YMqudE6PR7YOtv6E4UBA03NZIR7H6ccu4.6BoAtGQCq&shareID=284717
     */
    public static void modifyGroupProtect(Context context, String group_id, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .modifyGroupProtect(TokenUtils.getTokenHeader(), group_id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /*
     *   设置消息免打扰
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48228469&shareCode=Va3gRz&shareToken=$2y$10$RTG0wyE~2FqTrDOUBOcEduNOEhO.Yf.sAM6Wak8bciXEaOZKgzwHWbC&shareID=284717
     */
    public static void messageIgnore(Context context, String group_id, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .messageIgnore(TokenUtils.getTokenHeader(), group_id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


    /*
     *   退出群组: 群主无法使用
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48228469&shareCode=Va3gRz&shareToken=$2y$10$RTG0wyE~2FqTrDOUBOcEduNOEhO.Yf.sAM6Wak8bciXEaOZKgzwHWbC&shareID=284717
     */
    public static void logoutGroup(Context context, String group_id, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .logoutGroup(TokenUtils.getTokenHeader(), group_id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


    /*
     *   修改群组验证方式
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48228469&shareCode=Va3gRz&shareToken=$2y$10$RTG0wyE~2FqTrDOUBOcEduNOEhO.Yf.sAM6Wak8bciXEaOZKgzwHWbC&shareID=284717
     */
    public static void modifyJoinModeGroup(Context context, String group_id, String join_mode, String join_question1, BaseObserver<BaseEmptyBean> observer) {

        APIRequest
                .getRequestInterface()
                .modifyJoinModeGroup(TokenUtils.getTokenHeader(), group_id, join_mode, join_question1)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


    /*
     *   修改搜群方式
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48283839&shareCode=Va3gRz&shareToken=$2y$10$RTG0wyE~2FqTrDOUBOcEduNOEhO.Yf.sAM6Wak8bciXEaOZKgzwHWbC&shareID=284717
     */
    public static void modifyPropertyGroup(Context context, String group_id, String group_property, BaseObserver<BaseEmptyBean> observer) {

        APIRequest
                .getRequestInterface()
                .modifyPropertyGroup(TokenUtils.getTokenHeader(), group_id, group_property)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


    /*
     *   修改找群开关
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48295215&shareCode=Va3gRz&shareToken=$2y$10$RTG0wyE~2FqTrDOUBOcEduNOEhO.Yf.sAM6Wak8bciXEaOZKgzwHWbC&shareID=284717
     */
    public static void modifyFindswitchGroup(Context context, String group_id, BaseObserver<BaseEmptyBean> observer) {

        APIRequest
                .getRequestInterface()
                .modifyFindswitchGroup(TokenUtils.getTokenHeader(), group_id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


    /*
     *   修改找群开关
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48295215&shareCode=Va3gRz&shareToken=$2y$10$RTG0wyE~2FqTrDOUBOcEduNOEhO.Yf.sAM6Wak8bciXEaOZKgzwHWbC&shareID=284717
     */
    public static void getHxGroupInfo(Context context, String group_id, BaseObserver<GroupInfoBean> observer) {

        APIRequest
                .getRequestInterface()
                .getHxGroupInfo(TokenUtils.getTokenHeader(), group_id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


    /*
     *   群组邀请新成员
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48212053&shareCode=Va3gRz&shareToken=$2y$10$RTG0wyE~2FqTrDOUBOcEduNOEhO.Yf.sAM6Wak8bciXEaOZKgzwHWbC&shareID=284717
     */
    public static void inviteGroupMember(Context context, String group_id, String member_ids, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .inviteGroupMember(TokenUtils.getTokenHeader(), group_id, member_ids)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


    /*
     *   群组删除成员
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48220315&shareCode=Va3gRz&shareToken=$2y$10$RTG0wyE~2FqTrDOUBOcEduNOEhO.Yf.sAM6Wak8bciXEaOZKgzwHWbC&shareID=284717
     */
    public static void deleteGroupMember(Context context, String group_id, String member_ids, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .deleteGroupMember(TokenUtils.getTokenHeader(), group_id, member_ids)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /*
     *   投诉群组
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48263404&shareCode=Va3gRz&shareToken=$2y$10$UqvpXk54T9YMqudE6PR7YOtv6E4UBA03NZIR7H6ccu4.6BoAtGQCq&shareID=284717
     */
    public static void complaintGroup(Context context, String group_id, String reason, String chatevidence, String evidenceimages, String content, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .complaintGroup(TokenUtils.getTokenHeader(), group_id, reason, chatevidence, evidenceimages, content)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /*
     *   删除群组
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48338573&shareCode=Va3gRz&shareToken=$2y$10$UqvpXk54T9YMqudE6PR7YOtv6E4UBA03NZIR7H6ccu4.6BoAtGQCq&shareID=284717
     */
    public static void deleteGroup(Context context, String group_id, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .deleteGroup(TokenUtils.getTokenHeader(), group_id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


    /*
     *   退出群组(群主无法使用)
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48239860&shareCode=Va3gRz&shareToken=$2y$10$UqvpXk54T9YMqudE6PR7YOtv6E4UBA03NZIR7H6ccu4.6BoAtGQCq&shareID=284717
     */
    public static void exitGroup(Context context, String group_id, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .exitGroup(TokenUtils.getTokenHeader(), group_id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /*
     *   修改二维码开关
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48383769&shareCode=Va3gRz&shareToken=$2y$10$.C~2Ftw.C2XTkF98F6NRfWl.LRprCAdRE6zJR7t1V11WxqppovFzfa.&shareID=284717
     */
    public static void modifyQrGroup(Context context, String group_id, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .modifyQrGroup(TokenUtils.getTokenHeader(), group_id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /*
     *   整个群组禁言
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48229874&shareCode=Va3gRz&shareToken=$2y$10$RTG0wyE~2FqTrDOUBOcEduNOEhO.Yf.sAM6Wak8bciXEaOZKgzwHWbC&shareID=284717
     */
    public static void muteGroup(Context context, String group_id, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .muteGroup(TokenUtils.getTokenHeader(), group_id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


    /*
     *   解除整个群组禁言
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48229875&shareCode=Va3gRz&shareToken=$2y$10$RTG0wyE~2FqTrDOUBOcEduNOEhO.Yf.sAM6Wak8bciXEaOZKgzwHWbC&shareID=284717
     */
    public static void relieveMuteGroup(Context context, String group_id, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .relieveMuteGroup(TokenUtils.getTokenHeader(), group_id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


    /*
     *   禁言群成员
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48229874&shareCode=Va3gRz&shareToken=$2y$10$RTG0wyE~2FqTrDOUBOcEduNOEhO.Yf.sAM6Wak8bciXEaOZKgzwHWbC&shareID=284717
     */
    public static void muteGroupMembres(Context context, String group_id, String member_ids, int duration, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .muteGroupMembres(TokenUtils.getTokenHeader(), group_id, member_ids, duration)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


    /*
     *   解除禁言群成员
     *   api:  https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48229275&shareCode=Va3gRz&shareToken=$2y$10$RTG0wyE~2FqTrDOUBOcEduNOEhO.Yf.sAM6Wak8bciXEaOZKgzwHWbC&shareID=284717
     */
    public static void relieveMuteGroupMembres(Context context, String group_id, String member_ids, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .relieveMuteGroupMembres(TokenUtils.getTokenHeader(), group_id, member_ids)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


    /*
     *   群组待审核列表
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48335821&shareCode=Va3gRz&shareToken=$2y$10$UqvpXk54T9YMqudE6PR7YOtv6E4UBA03NZIR7H6ccu4.6BoAtGQCq&shareID=284717
     */
    public static void joinGroupApplyList(Context context, String group_id, BaseObserver<List<MembersBean>> observer) {
        APIRequest
                .getRequestInterface()
                .joinGroupApplyList(TokenUtils.getTokenHeader(), group_id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

    /*
     *   审核用户
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48335876&shareCode=Va3gRz&shareToken=$2y$10$UqvpXk54T9YMqudE6PR7YOtv6E4UBA03NZIR7H6ccu4.6BoAtGQCq&shareID=284717
     */
    public static void examineJoinGroupApply(Context context, String group_id, String member_id, String state, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .examineJoinGroupApply(TokenUtils.getTokenHeader(), group_id, member_id, state)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


    /*
     *   设置群组管理员
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48220379&shareCode=Va3gRz&shareToken=$2y$10$RTG0wyE~2FqTrDOUBOcEduNOEhO.Yf.sAM6Wak8bciXEaOZKgzwHWbC&shareID=284717
     */
    public static void addAdminGroup(Context context, String group_id, String member_ids, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .addAdminGroup(TokenUtils.getTokenHeader(), group_id, member_ids)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


    /*
     *   删除群组管理员
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48220382&shareCode=Va3gRz&shareToken=$2y$10$RTG0wyE~2FqTrDOUBOcEduNOEhO.Yf.sAM6Wak8bciXEaOZKgzwHWbC&shareID=284717
     */
    public static void deleteAdminGroup(Context context, String group_id, String member_ids, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .deleteAdminGroup(TokenUtils.getTokenHeader(), group_id, member_ids)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }


    /*
     *   转让群组
     *   api: https://www.eolink.com/share/project/api/detail?groupID=-1&apiID=48228580&shareCode=Va3gRz&shareToken=$2y$10$RTG0wyE~2FqTrDOUBOcEduNOEhO.Yf.sAM6Wak8bciXEaOZKgzwHWbC&shareID=284717
     */
    public static void transferAdminGroup(Context context, String group_id, String member_id, BaseObserver<BaseEmptyBean> observer) {
        APIRequest
                .getRequestInterface()
                .transferAdminGroup(TokenUtils.getTokenHeader(), group_id, member_id)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(observer);
    }

}
